package com.xx.controller;

import com.xx.entity.Student;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController //组合注解 包含了@Controller和@ResponseBody两个注解
public class StudentController {
    //get请求单参数
    @GetMapping("/getStudent")
    public String getStudent(String name){
        System.out.println("参数"+name);

        return "getStudent";
    }

    //get请求单参数
    @GetMapping("/getStudent")
    public String getStudent(@RequestParam("studentName") String name, Integer age , String sex){
        System.out.println("姓名 ==> "+name);
        System.out.println("年纪 ==> "+age);
        System.out.println("性别 ==> "+sex);

        return "getStudent";
    }
    //post 请求 form表单数据
    @PostMapping("postStudent")
    public String postStudent(@RequestParam("getStudent") String name,Integer age ,String sex){
        System.out.println("姓名 ==> "+name);
        System.out.println("年纪 ==> "+age);
        System.out.println("性别 ==> "+sex);

        return "postStudent";
    }

    //对象参数
    @GetMapping("getPojoStudent")
    public String getPojoStudent(Student student){
        System.out.println("PojoStudent参数" + student);
        System.out.println("PojoStudent嵌套参数" + student.getCourse());

        return  "getPojoStudent!";
    }

    //接收数组请求的参数
    @GetMapping("arraysStudent")
    public String arraysStudent(String[] hobbys){
        System.out.println("arraysStudent参数" + Arrays.toString(hobbys));

        return  "arraysStudent!";
    }

    //接收集合参数
    @GetMapping("listStudent")
    //@RequestParam绑定参数     形参注解
    public String listStudent(@RequestParam("hobbes") List<String> hobbys){
        System.out.println("listStudent参数" + hobbys);

        return  "listStudent!";
    }

    //接收前端的json数据
    @GetMapping("getJsonStudent")
    public String getJsonStudent(@RequestBody Student student){
        System.out.println("json数据传递====>" + student);
        System.out.println("json数据传递====>" + student.getCourse());

        return "getJsonStudent";
    }

    //接收json数组
    @PostMapping("/postJsonStudent")
    public String postJsonStudent(@RequestBody List<Student> students){
        System.out.println("json数据传递====>" +students);
        return "postJsonStudent";
    }
}
